<template>
    <LModalForm 
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        ref="attribute" 
        :formAttributes="formAttributes" 
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @clickEventHandler="clickEventHandler"
        @changeEventHandler="changeEventHandler"></LModalForm>

</template>

<script>
import LModalForm from "@/components/lt/form/LModalForm"
import pageSetting from '@/components/lt/codeGenerator/pageSetting'
import pick from 'lodash.pick'


export default {
    name:'TableActionAttribute',
    components:{
        LModalForm
    },
    props:{
        action:{
            type:Array,
            default:()=>[]
        },
    },
    data(){
        return{
            pageSetting,
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'actionName',label:'操作名称',component:pageSetting.常量.表单组件类型.单行文本,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'actionMethod',label:'操作方法',component:pageSetting.常量.表单组件类型.单行文本,rules: [{ required: true, message: '不能为空!' }]},
                  
                 ]
                },
              ]

            }


        }
    },
    methods:{
       
        edit (record) {
            this.visible = true
            this.model=record
            this.$nextTick(() => {
                this.$refs.attribute.getForm().setFieldsValue(pick(this.model,'actionName','actionMethod'))
            })
            
        },
        handleOk(){
            this.$refs.attribute.getForm().validateFields((err, values) => {
                if (!err) {
                    this.model = Object.assign(this.model, values)
                    let count = 0
                    if(this.action && this.action.length>0){
                        for (let a of this.action) {
                            if(a.actionName==this.model.actionName || a.actionMethod==this.model.actionMethod){
                                count++
                            }
                        }
                        // console.log(count)
                        // if(count>1){
                        //     this.$message.warning("操作名称和方法不能重复")
                        //     return false
                        // }
                        
                    }
                    if(count==0){
                        this.action.push(this.model)
                    }
                    
                    this.close()
                }
            })
            
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close')
            this.visible = false;
        },
       
        /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
            
            
        },
        clickEventHandler(field,form){
            
        }
    },
    created(){
        
    },
}
</script>